;
var _pageUrl = "/htmlWeb/advAudit/list";
var pageGrid;
function goView(id) {
    var page_Obj_view = null;
    if (page_Obj.page_type == 1) {
        page_Obj_view = {
            page_type: 2,//列表类型，1 广告类，2广告栏目，3广告
            id: null,//编辑数据的ID
            pId: id,//上级ID
            pId1: 0,
            province: '',//省
            city: '',//市
            district: ''//区县
        };
    } else if (page_Obj.page_type == 2) {
        page_Obj_view = {
            page_type: 3,//列表类型，1 广告类，2广告栏目，3广告
            id: null,//编辑数据的ID
            pId: id,//上级ID
            pId1: page_Obj.pId,
            province: '',//省
            city: '',//市
            district: ''//区县
        };
    }
    $.ajaxSetup({cache: false});
    $(".mainDiv").load('htmlWeb/systemAdverListHtml', '', function () {
        page_Obj = page_Obj_view;
        $.getScript("../../by-webhtml/assets/js/system/system_adverList.js");
    });
}
function init() {
    _init_area();
    $(".conBut").click(function () {
        pageGrid.search({province: $("#province").val(), city: $("#city").val(), district: $("#district").val(),isCheck: $("#isCheck").val()});
    });
}
function isCheckedAd(id) {
    $.ajax({
        url:"/htmlWeb/adv/setIsChecked",
        type:'POST',
        dataType:"json",
        data:{
            id: id,isCheck:1
        },
        success:function(result){
            if(result.msg == 'success'){
                alert("审核成功");
                $(".conBut").click();
            }else {
                alert("审核失败");
            }
        }
    });
}
function isNotCheckedAd(id) {
    $.ajax({
        url:"/htmlWeb/adv/setIsChecked",
        type:'POST',
        dataType:"json",
        data:{
            id: id, isCheck:2
        },
        success:function(result){
            if(result.msg == 'success'){
                alert("审核不通过成功");
                $(".conBut").click();
            }else {
                alert("审核不通过失败");
            }
        }
    });
}
function pageBar() {
    pageGrid = $("#pager").createPage({
        url: _pageUrl,
        params: {
            province: $("#province").val(),
            city: $("#city").val(),
            district: $("#district").val(),
            isCheck: $("#isCheck").val()
        },
        ajaxBackFn: function (data) {
            var _gridHtml = '';
            $.each(data.rows, function (index, row) {
                if(loginUserType == 5 && index<=3){
                    return true;
                }
                _gridHtml += '<tr>' +
                    '<td><input type="hidden" class="rowid" value=\"' + row.id + '\"><p>' + row.id + '</p></td>' +
                    '<td><p>' + row.name + '</p></td>' +
                    '<td><p>' + (row.imgUrl == null ? "" : '<img src="'+ _imgesByUrl+ row.imgUrl + '" width="60px" height="40px"/>') + '</p></td>' +
                    '<td><p>' + row.url + '</p></td>' +
                    '<td><p>' + (row.province == null ? "" : row.province) + '</p></td>' +
                    '<td><p>' + (row.city == null ? "" : row.city) + '</p></td>' +
                    '<td><p>' + row.updateTimeStr + '</p></td>' +
                    '<td><p>' + getIsChecked(row.isCheck) + '</p></td>' +
                    '<td><span class="userSpan"><p>';
                if(loginUserType == 1){
                    if(row.isCheck == -1){
                        _gridHtml += '<a href="javascript:isCheckedAd(' + row.id +')">审核通过</a>';
                        _gridHtml += '<a href="javascript:isNotCheckedAd(' + row.id + ')">审核不通过</a>';
                    }
                }
                _gridHtml += '</p></span></td></tr>';
            });
            $("#advGrid tr:not(:first)").html("");
            $('#advGrid').append(_gridHtml);
        }
    });
}
function getIsChecked(s) {
    if(s == -1){
        return "待审核";
    }else if(s == 1){
        return "审核通过";
    }else {
        return "审核不通过";
    }
}
$(function () {
    init();
    pageBar();
});